home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / mystic.zip / PAS4.DOC < prev    next >
Text File  |  1986-02-27  |  8KB  |  401 lines

  1.  
  2.         Mystic Pascal  User Manual                                      22
  3.  
  4.  
  5.         7.  Multi-tasking Support
  6.  
  7.              Mystic  Pascal  is  a  multi-tasking  system.   The  editor, 
  8.         compiler, system display and other major components are processes 
  9.         which execute concurrently.   Pascal programs may also use multi-
  10.         tasking.
  11.  
  12.              In  Mystic Pascal any global procedure may be started as  an 
  13.         independent  process  by the START builtin procedure.   Up to  50 
  14.         Pascal   procedures  may  execute   concurrently.    The   system 
  15.         automatically  switches  among the concurrent procedures as  they 
  16.         execute.   Procedures  are  allowed to execute if  they  are  not 
  17.         in a wait state and based on their static priority and the length 
  18.         of  time  they  have  been waiting.   Even  the  lowest  priority 
  19.         procedure will execute.
  20.  
  21.              Concurrent  procedures  will  run  until the  final  END  is 
  22.         reached.   At  that time the process will be deleted.   The  same 
  23.         Pascal source procedure may be started more than once -- a single 
  24.         source   procedure  may  have  many   incarnations.    Concurrent 
  25.         procedures  may be recursive,  may call  global  procedures,  may 
  26.         access global variables and may START global procedures.
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.         Section 7:   Multi-tasking Support
  58.  
  59.         Mystic Pascal  User Manual                                      23
  60.  
  61.  
  62.         7.1  Message Passing
  63.  
  64.              Concurrent  procedures may communicate by passing  messages.  
  65.         Messages  are  processed  by  Mystic  Pascal's  queue  management 
  66.         system.   This  is  not  only for communication but  also  allows 
  67.         efficient  synchronization  among the  concurrent  procedures  -- 
  68.         attempting  to  receive a message from an empty queue causes  the 
  69.         procedure to enter a wait state until a message arrives.
  70.  
  71.              Queues  are  first-in-first-out (FIFO)  storage  mechanisms.  
  72.         The queue messages are stored in the dynamic storage area.  
  73.  
  74.              As  an example,  consider a concurrent procedure  LOG  whose 
  75.         purpose  is  to write one line messages to a printer.   LOG  must 
  76.         accept  messages from several other concurrent  procedures.   LOG 
  77.         has  its own input queue from which it receives messages  and  to 
  78.         which  other procedures send messages.   LOG can ensure that only 
  79.         one user at a time (itself) does printing.  If several procedures 
  80.         could  print  at  the same  time,  their  messages  could  become 
  81.         interleaved resulting in a garbled printout.
  82.  
  83.                   PROCEDURE LOG;
  84.                   LABEL 100;
  85.  
  86.                   BEGIN
  87.                   QUEUE('LOGQ    ');
  88.                   100:  RECEIVE('LOGQ    ', MSG);
  89.                   {print the message}
  90.                   GOTO 100;
  91.                   END;
  92.  
  93.              Careful planning is necessary when concurrent procedures may 
  94.         access a printer, console or disk files at the same time.  Having 
  95.         one concurrent procedure handle all accesses is a common solution 
  96.         to this issue.  This is related to the concept of a "monitor."
  97.  
  98.              Before a queue may be used,  it must be created by the QUEUE 
  99.         builtin  procedure.   Each queue must have a unique 8 byte  name.  
  100.         The builtin queue management procedures are:
  101.  
  102.              QUEUE     create a new queue
  103.              SEND      store a message on a queue
  104.              RECEIVE   get a message from a queue
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.         Section 7:   Multi-tasking Support
  115.  
  116.         Mystic Pascal  User Manual                                      24
  117.  
  118.  
  119.         7.2  START
  120.  
  121.         START( procedure_name, process_name, stack_size );
  122.  
  123.              The  START  procedure  is  used  to  initiate  a  concurrent 
  124.         procedure.   The  procedure  will execute as a  separate  process 
  125.         until it terminates by reaching its final END.
  126.  
  127.              The  process_name is an 8 character ASCII field.   This name 
  128.         is  displayed in the system display and is used in  the  PRIORITY 
  129.         builtin  procedure.   A  single Pascal procedure may  be  started 
  130.         several times.  Each start must use a unique process name.
  131.  
  132.              The  stack_size is an integer expression.   It specifies the 
  133.         amount  of space to be allocated in paragraphs - multiples of  16 
  134.         bytes.   Enough space must be included for this procedure's local 
  135.         variables,  the  local variables of all procedures it  calls  and 
  136.         additional stack space for evaluating expressions.
  137.  
  138.              If  the  concurrent  procedure  is recursive  or  calls  any 
  139.         recursive procedures,  great caution should be used in estimating 
  140.         the  stack_size  or an insufficient storage  run-time  error  may 
  141.         result.
  142.  
  143.              The  priority of a concurrent procedure is initially set  to 
  144.         20.  This may be modified by the PRIORITY builtin procedure.
  145.  
  146.  
  147.  
  148.              START( LOG, 'LOGPROC ', 30 );
  149.              START( PRINTER, 'PRINTER ', 100 );
  150.              START( DOWJONESPORT, 'DJP     ', 200 );
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.         Section 7:   Multi-tasking Support
  172.  
  173.         Mystic Pascal  User Manual                                      25
  174.  
  175.  
  176.         7.3  PRIORITY                                       ** 1.6 **
  177.  
  178.         PRIORITY( process_name, priority );
  179.  
  180.              The PRIORITY procedure is used to modify the static priority 
  181.         of  a concurrent procedure which has been started.   The  initial 
  182.         priority is 20.   The priority parameter is an integer expression 
  183.         in the range 1 to 64.  
  184.  
  185.  
  186.  
  187.              PRIORITY( 'LOGPROC ', 10 );
  188.              PRIORITY( 'DJP     ', 64 );
  189.              PRIORITY( 'CHESS A ', 40 );
  190.              PRIORITY( 'CHESS B ', 35 );
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.         Section 7:   Multi-tasking Support
  229.  
  230.         Mystic Pascal  User Manual                                      26
  231.  
  232.  
  233.         7.4  QUEUE                                          ** 1.6 **
  234.  
  235.         QUEUE( queue_name );
  236.  
  237.              The QUEUE procedure creates a new queue for message passing.  
  238.         Each  queue  is identified by a unique 8 byte queue  name.   This 
  239.         name does not have to be ASCII.
  240.  
  241.  
  242.  
  243.              QUEUE( 'LOGQ    ' );
  244.              QUEUE( 'ERRORMSG' );
  245.              QUEUE( 'COMMANDS' );
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.         Section 7:   Multi-tasking Support
  286.  
  287.         Mystic Pascal  User Manual                                      27
  288.  
  289.  
  290.         7.5  SEND                                           ** 1.6 **
  291.  
  292.         SEND( queue_name, variable );
  293.  
  294.              The SEND procedure stores a message on a queue.   The  queue 
  295.         must have been created by the QUEUE procedure.
  296.  
  297.              The  concurrent  procedure that issues the SEND will  resume 
  298.         execution immediately unless the space allowed for this queue  is 
  299.         full.   Then  the issuer is placed in a wait state until space is 
  300.         released  by another concurrent procedure removing messages  from 
  301.         the queue.
  302.  
  303.  
  304.  
  305.              SEND('RED ALRT','EEG INPUT CORRELATES 1.0 WITH PREDICTION');
  306.              SEND( 'TREESORT', ROOTPTR );
  307.              SEND( 'COMPILER', SOURCEARRAY );
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.         Section 7:   Multi-tasking Support
  343.  
  344.         Mystic Pascal  User Manual                                      28
  345.  
  346.  
  347.         7.6  RECEIVE                                        ** 1.6 **
  348.  
  349.         RECEIVE( queue_name, variable );
  350.  
  351.              The  RECEIVE procedure removes the oldest message  from  the 
  352.         specified  queue.   If  no messages are present,  the  issuer  is 
  353.         placed in a wait state until a message arrives.
  354.  
  355.  
  356.  
  357.  
  358.              RECEI